﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using FTchina.Library;

public partial class ui_zhuayoubaobiao_Default : System.Web.UI.Page
{
    PWMIS.DataProvider.Data.AdoHelper ado = PWMIS.DataProvider.Adapter.MyDB.GetDBHelperByConnectionName("DYDB");

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            GetData();
          
        }
    }


    protected void GetData()
    {

        string sql = @"SELECT * FROM jtkh_tmp1 t WHERE t.ACCT_ID IN(
SELECT a.ACCT_ID
FROM jtkh_tmp1 a 
WHERE a.END_CYC_ID>=TO_CHAR(SYSDATE, 'yyyymm') 	 
AND a.net_type_code in ('17','33')
--AND a.ACCT_ID=1610010712407973
GROUP BY a.ACCT_ID
HAVING count(a.USER_ID)>=5
)
ORDER BY t.ACCT_ID ";
        Grid1.PageSize = 20;
        int count = ado.ExecuteDataSet(sql).Tables[0].Rows.Count;
        string singlepage = PWMIS.Common.SQLPage.MakeSQLStringByPage(PWMIS.Common.DBMSType.Oracle, sql, "1=1", Grid1.PageSize, Grid1.PageIndex+1, count);


        Grid1.DataSource = ado.ExecuteDataSet(singlepage);
        Grid1.DataBind();
    }


    protected string GetTopdpt(string DEVELOP_DEPART_ID)
    {
        string tmp = string.Empty;
        GetGdept(DEVELOP_DEPART_ID, out tmp);
        return tmp;


    }



    private void GetGdept(string DEPART_CODE, out string dptName)
    {
        string sql = @"SELECT  t.DEPART_CODE,t.DEPART_NAME,t.DEPART_LEVEL,t.PARENT_DEPART_ID
  FROM DYJF.TD_M_DEPART T
 WHERE T.RSVALUE2 = '0546'  
   AND T.VALIDFLAG = '0' 
	 AND t.DEPART_CODE='" + DEPART_CODE + "'";

        DataTable dt = ado.ExecuteDataSet(sql).Tables[0];
        LogHelper.Debug(dt.Rows[0]["DEPART_LEVEL"].ToString()+"--" + dt.Rows[0]["DEPART_NAME"].ToString() + "--"+dt.Rows[0]["PARENT_DEPART_ID"].ToString());

        if (dt.Rows[0]["DEPART_LEVEL"].ToString() == "3" || dt.Rows[0]["DEPART_NAME"].ToString() == "东营市分公司集团客户事业部一部" || dt.Rows[0]["DEPART_NAME"].ToString() == "东营市分公司集团客户事业部二部")
        {
            dptName = dt.Rows[0]["DEPART_NAME"].ToString();
        }
        else
        {
            GetGdept(dt.Rows[0]["PARENT_DEPART_ID"].ToString(), out dptName);
        }

    }
}